'use strict';

const sqlConfig = require('./selfConfig/sqlConfig')
const { mysql: mysqlConfig, redis: redisConfig } = sqlConfig.prodConfig

/**
 * @param {Egg.EggAppInfo} appInfo app info
 */
module.exports = appInfo => {
  const config = (exports = {});

  config.cluster = {
    listen: {
      port: 8455,
      hostname: '0.0.0.0',
    },
  };

  config.io = {
    init: {}, // passed to engine.io
    namespace: {
      '/': {
        connectionMiddleware: [ 'connect' ],
        packetMiddleware: [ 'packer' ],
      },
    },
  };

  config.sequelize = {
    datasources: [
      {
        delegate: 'model',
        baseDir: 'model',

        host: mysqlConfig.host,
        username: mysqlConfig.username,
        password: mysqlConfig.password,
        port: mysqlConfig.port,

        database: mysqlConfig.database,
        define: {
          underscored: true,
          createdAt: 'created_at',
          updatedAt: 'updated_at',
          deletedAt: 'deleted_at',
        },

        dialect: 'mysql',
        pool: {
          max: 100,
          min: 0,
          acquire: 30000,
          idle: 30000,
        },
        benchmark: true,
        timezone: '+08:00', // 东八区
      },
    ],
  };

  config.redis = {
    client: {
      port: redisConfig.port,
      host: redisConfig.host,
      password: redisConfig.password,
      db: redisConfig.db
    },
  };

  return { ...config };
};
